<template>
	<view >
		<!-- 显示聊天时间 -->
		<view v-if="shortTime" class="py-2 flex align-center justify-center font text-light-muted">{{shortTime}}</view>
		<!-- 聊天气泡 -->
		<view class="flex align-start px-2 my-2 " :style="isSelf?'flex-direction:row-reverse':''">
			<image class="rounded-circle" :src="item.avatar" style="height: 100rpx;width: 100rpx;"></image>
			<view class="bg-light rounded p-2 mx-2" style="max-width: 400rpx;min-width: 100rpx;"
			:style="isSelf?'background-color:#2BA245':''"
			>{{item.data}}</view>
		</view>
	</view>
</template>

<script>
	//当前用户登录id uid  假设 =1 为自己登录
	const uid= 1
	import $T from '@/common/time.js'
	export default{
		props:{
			item:Object,
			index:Number,
			pretime:[Number,String]
		},
		computed:{
			//判断是否用户本人登录
			isSelf(){
				return uid === this.item.user_id
			},
			//转换时间  300s 以内 不显示聊天时间 传入当前消息时间 和之前一条消息的时间
			shortTime(){
				return $T.getChatTime(this.item.create_time,this.pretime)
			}
		}
	}
</script>

<style>
</style>